package com.toubutu.audio.controller;

import com.toubutu.anno.LoginRequired;
import com.toubutu.common.BusinessException;
import com.toubutu.common.Result;
import com.toubutu.common.StatusCodeEnum;
import com.toubutu.service.oss.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author 戒躁
 * @version 1.0
 * @date 2023年11月02日 18:01
 */
@Api(tags = "文件上传接口")
@RestController
//@LoginRequired
public class FileUploadController {
    @Resource
    private OssService ossService;

    @PostMapping("/upload")
    @ApiOperation("文件上传")
    public Result<OssService.UploadResult> upload(MultipartFile file){
        try {
            OssService.UploadResult upload =
                    ossService.upload(file.getOriginalFilename(), file.getInputStream());
            return Result.ok(upload);
        }catch (Exception e){
            throw new BusinessException(StatusCodeEnum.CODE_ERROR.getCode(),"文件上传异常");
        }
    }
}
